package com.sc.nft.admin.controller;

import com.sc.nft.admin.request.*;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.vo.OrderGasShareConfigVO;
import com.sc.nft.entity.vo.OrderGasVO;
import com.sc.nft.service.OrderGasService;
import com.sc.nft.service.OrderGasShareConfigService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author 刘国航
 * @desc 上链费分红
 * @since 2024/10/21 11:27
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/orderGas")
@Api(tags = "上链费分红")
public class OrderGasController {

    private final OrderGasShareConfigService orderGasShareConfigService;
    private final OrderGasService orderGasService;

    @PostMapping(value = "/createShareConfig", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新建分红配置", notes = "新建分红配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteById(@RequestBody @Valid OrderGasCreateShareConfigRequest request) {
        orderGasShareConfigService.createShareConfig(request.getShareName(), request.getCollectionId(), request.getShareRatio());
        return Result.success();
    }

    @PostMapping(value = "/updateShareConfig", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "更新分红配置", notes = "更新分红配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateShareConfig(@RequestBody @Valid OrderGasUpdateShareConfigRequest request) {
        orderGasShareConfigService.updateShareConfig(request.getId(), request.getShareName(), request.getShareRatio());
        return Result.success();
    }

    @PostMapping(value = "/updateStatus", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "更新分红配置状态", notes = "更新分红配置状态", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateStatus(@RequestBody @Valid OrderGasUpdateShareConfigStatusRequest request) {
        orderGasShareConfigService.updateStatus(request.getId(), request.getStatus());
        return Result.success();
    }

    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分页查询", notes = "分页查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<OrderGasShareConfigVO> page(@RequestBody OrderGasConfigPageRequest request) {
        return PageResult.success(orderGasShareConfigService.page(request.toMp(), request.getShareName(), request.getCollectionId()));
    }

    @PostMapping(value = "/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "详情", notes = "详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<OrderGasShareConfigVO> detail(@RequestBody @Valid IdRequest request) {
        return Result.success(orderGasShareConfigService.detail(request.getId()));
    }

    @PostMapping(value = "/getGas", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取上链费分红池", notes = "获取上链费分红池", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<OrderGasVO> getGas() {
        return Result.success(orderGasService.getGas());
    }

}
